<?php

	function dieError( $msg ) {
		$msg = array( "result" => 0, "errorMsg" => $msg );
		die( json_encode($values) );
	}

	function dieSuccess( $msg, $values=false ) {
		if ( !$values ) $values = array();
		$values["result"] = 1;
		if ( !empty($msg) ) $values["successMsg"] = $msg;
		die( json_encode($values) );
	}

	function query( $sql ) {
		$result = mysql_query($sql);
		if ( !$result ) dieError( "MySQL error: ".mysql_error() );
		return $result;
	}

?>
